package com.xiaoma.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaoma.weblog.common.domain.dos.UserDO;
import org.apache.catalina.User;

import java.time.LocalDateTime;

/**
 * @ClassName UserMapper
 * @Description:
 * @Author: 小马
 * @CreateDate: 2025/3/27 13:55
 * @Version: 1.0
 */
public interface UserMapper extends BaseMapper<UserDO> {

    default UserDO findByUsername(String username) {
        LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserDO::getUsername, username);
        return selectOne(wrapper);
    }

    default int updatePassword(String username, String password) {
        LambdaUpdateWrapper<UserDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.set(UserDO::getPassword, password);
        lambdaUpdateWrapper.set(UserDO::getUpdateTime, LocalDateTime.now());
        lambdaUpdateWrapper.eq(UserDO::getUsername, username);
        return update(null, lambdaUpdateWrapper);
    }

}